package com.fuzamei.rent.sender;

import org.apache.log4j.Logger;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class Sender {
    @Autowired
    private AmqpTemplate rabbitTemplate;

    Logger logger = Logger.getLogger(Sender.class);

    public void send(){
        String context = "hello" + new Date();
        logger.info("sender："+context);
        this.rabbitTemplate.convertAndSend("hello",context);
    }

    public String send(String message){
        try {
            this.rabbitTemplate.convertAndSend("hello", message);
            return "发送消息成功";
        }catch (Exception e){
            e.printStackTrace();
            return "发送消息失败";
        }

    }
}
